package com.ruoyi.project.module.categoryinfo.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.framework.aspectj.lang.annotation.Log;
import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
import com.ruoyi.project.module.categoryinfo.domain.Categoryinfo;
import com.ruoyi.project.module.categoryinfo.service.ICategoryinfoService;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.page.TableDataInfo;
import com.ruoyi.framework.web.domain.AjaxResult;

/**
 * 菜单 信息操作处理
 * 
 * @author ruoyi
 * @date 2018-11-11
 */
@Controller
@RequestMapping("/module/categoryinfo")
public class CategoryinfoController extends BaseController
{
    private String prefix = "module/categoryinfo";
	
	@Autowired
	private ICategoryinfoService categoryinfoService;
	
	@RequiresPermissions("module:categoryinfo:view")
	@GetMapping()
	public String categoryinfo()
	{
	    return prefix + "/categoryinfo";
	}
	
	/**
	 * 查询菜单列表
	 */
	@RequiresPermissions("module:categoryinfo:list")
	@PostMapping("/list")
	@ResponseBody
	public TableDataInfo list(Categoryinfo categoryinfo)
	{
		startPage();
        List<Categoryinfo> list = categoryinfoService.selectCategoryinfoList(categoryinfo);
		return getDataTable(list);
	}
	
	/**
	 * 新增菜单
	 */
	@GetMapping("/add")
	public String add()
	{
	    return prefix + "/add";
	}
	
	/**
	 * 新增保存菜单
	 */
	@RequiresPermissions("module:categoryinfo:add")
	@Log(title = "菜单", businessType = BusinessType.INSERT)
	@PostMapping("/add")
	@ResponseBody
	public AjaxResult addSave(Categoryinfo categoryinfo)
	{		
		return toAjax(categoryinfoService.insertCategoryinfo(categoryinfo));
	}

	/**
	 * 修改菜单
	 */
	@GetMapping("/edit/{id}")
	public String edit(@PathVariable("id") Integer id, ModelMap mmap)
	{
		Categoryinfo categoryinfo = categoryinfoService.selectCategoryinfoById(id);
		mmap.put("categoryinfo", categoryinfo);
	    return prefix + "/edit";
	}
	
	/**
	 * 修改保存菜单
	 */
	@RequiresPermissions("module:categoryinfo:edit")
	@Log(title = "菜单", businessType = BusinessType.UPDATE)
	@PostMapping("/edit")
	@ResponseBody
	public AjaxResult editSave(Categoryinfo categoryinfo)
	{		
		return toAjax(categoryinfoService.updateCategoryinfo(categoryinfo));
	}
	
	/**
	 * 删除菜单
	 */
	@RequiresPermissions("module:categoryinfo:remove")
	@Log(title = "菜单", businessType = BusinessType.DELETE)
	@PostMapping( "/remove")
	@ResponseBody
	public AjaxResult remove(String ids)
	{		
		return toAjax(categoryinfoService.deleteCategoryinfoByIds(ids));
	}
	
}
